Button Customization

Override the Delete Button Handler

Description
This customization shows how to handle OnClick event for Delete button in a page.
Variables
Table Control
Select the table control displaying the records you want to delete
Table Name
Select the database table to which the table control is bound
Field Value Control
Select the field value control on which you want to perform check
Button Control
Select the delete button
Applies to
P_Button Control class
Code
 
''' 
''' Override the DeleteButton_Click() button handler method. Add custom logic that gets executed
''' on ${Button Control}_Click
''' 
Public Overrides Sub ${Button Control}_Click(ByVal sender As Object, ByVal args As System.Web.UI.ImageClickEventArgs)

      Try
         DbUtils.StartTransaction
		
		' Get selected records
         Dim recList() As ${Table Control}Row = Me.GetSelectedRecordControls()
		 
		 ' Loop through each selected record
         For Each rec As ${Table Control}Row In reclist
             
			' If the field contains value "11111", then the deletion of the record is cancelled and an error message is displayed; otherwise, the 
			' selected record is deleted   
			 If rec.${Field Value Control}.Text.Equals("11111") Then
					  
				BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "Cannot delete record", "Cannot delete record with ${Field Value Control} = " + rec.${Field Value Control}.Text)
				' Set the selection of the record to false so that the deletion of the record does not takes place.
			    rec.${Table Name}RecordRowSelection.Checked = False
						 
			 End If	
					
         Next
         Me.DeleteSelectedRecords(false)
         Me.Page.CommitTransaction(sender)
       Catch ex As Exception
              BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
              Me.Page.RollBackTransaction(sender)
       Finally
             DbUtils.CommitTransaction()
       End Try    
    
        
End Sub


 

Terms of Service Privacy Statement